package alfred.proctice.com.recycleview;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by Alfred on 2018/3/8.
 */

public class CommentBinder extends ItemViewBinder<DymanicAllBean.Dymanic.Comment,CommentBinder.ViewHolder> {
    public Context context;
    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        context = parent.getContext();
        return new ViewHolder(inflater.inflate(R.layout.item_comment,parent,false));
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull DymanicAllBean.Dymanic.Comment item) {
        String str;
        StringBuilder builder = new StringBuilder();
        if (getPosition(holder) == 3) {
            str = "查看全部" + getAdapter().getItemCount() + "评论....";
            builder.append(str);
        } else {
            str = item.name + ":";
            builder.append(str);
            builder.append(item.content);
        }
        holder.item_comment_tv.setText(StringUtils.setKeyWordColor(context,builder.toString(), str, R.color.color_theme));
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        public TextView item_comment_tv;
        public ViewHolder(View itemView) {
            super(itemView);
            item_comment_tv = itemView.findViewById(R.id.item_comment_tv);
        }
    }
}
